package com.tjetc.view.manage;

import com.tjetc.domain.Doctormessge;
import com.tjetc.domain.Newborn;
import com.tjetc.domain.Performance;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.DoctorMessageService;
import com.tjetc.service.DoctorService;
import com.tjetc.vo.AppDate;
import com.tjetc.vo.Result;

import java.util.List;
import java.util.Scanner;

public class MyselfView {
    private Scanner scanner=new Scanner(System.in);
    private DoctorMessageService doctorMessageService=ClientProxy.getProxyInstance(DoctorMessageService.class);
    private DoctorService doctorService=ClientProxy.getProxyInstance(DoctorService.class);
    public void start() {
        while (true){
            try {
                System.out.println("1.查看本人护理的新生儿");
                System.out.println("2.查看本人绩效");
                System.out.println("3.补充个人信息");
                System.out.println("4.修改个人信息");
                System.out.println("5.查看个人信息");
                System.out.println("0.返回上一级");
                int i=scanner.nextInt();
                switch (i){
                    case 1:
                        sel();
                        break;
                    case 2:
                        selPerson();
                        break;
                    case 3:
                        message();
                        break;
                    case 4:
                        upd();
                        break;
                    case 5:
                        selP();
                        break;
                    case 0:
                        return;
                }
            } catch (Exception e) {
                System.out.println("输入错误,请重新输入");
                scanner.nextLine();
            }
        }
    }

    private void selP() {
        int doctorId=AppDate.loginDoctor.getId();
        Doctormessge doctormessge= doctorMessageService.selP(doctorId);
        System.out.println(doctormessge);
    }

    private void upd() {
        int doctorId=AppDate.loginDoctor.getId();
        String name=AppDate.loginDoctor.getUsername();
        System.out.println("请输入修改后的年龄");
        int age=scanner.nextInt();
        System.out.println("请输入修改后的性别");
        String gender=scanner.next();
        if (!(gender.equals("男"))&&!(gender.equals("女"))) {
            System.out.println("输入错误");
        }else {
            String phone;
            while (true) {
                System.out.println("请输入修改后的手机号:");
                phone = scanner.next();
                if (!phone.matches("1[35789]\\d{9}")) {
                    System.out.println("手机号格式不正确,请重新输入");
                } else {
                    break;
                }
            }
            Doctormessge doctormessge = new Doctormessge();
            doctormessge.setName(name);
            doctormessge.setAge(age);
            doctormessge.setGender(gender);
            doctormessge.setPhone(phone);
            doctormessge.setDoctorId(doctorId);
            Result result=doctorMessageService.upd(doctormessge);
            System.out.println(result.getMsg());
        }

    }

    private void message() {
        int doctorId=AppDate.loginDoctor.getId();
        String name=AppDate.loginDoctor.getUsername();
        System.out.println("请输入年龄");
        int age=scanner.nextInt();
        System.out.println("请输入性别");
        String gender=scanner.next();
        if (!(gender.equals("男"))&&!(gender.equals("女"))){
            System.out.println("输入错误");
        }else {
            String phone;
            while (true) {
                System.out.println("请输入手机号:");
                phone = scanner.next();
                if (!phone.matches("1[35789]\\d{9}")) {
                    System.out.println("手机号格式不正确,请重新输入");
                } else {
                    break;
                }
            }
            Doctormessge doctormessge = new Doctormessge();
            doctormessge.setName(name);
            doctormessge.setAge(age);
            doctormessge.setGender(gender);
            doctormessge.setPhone(phone);
            doctormessge.setDoctorId(doctorId);
            Result result=doctorMessageService.add(doctormessge);
            System.out.println(result.getMsg());
        }
    }


    private void selPerson() {
        int id=AppDate.loginDoctor.getId();
        Performance performance=doctorMessageService.selPerson(id);
        System.out.println(performance);
    }

    private void sel() {
        int id=AppDate.loginDoctor.getId();
        List<Newborn> list=doctorMessageService.sel(id);
        for (Newborn newborn : list) {
            System.out.println(newborn);
        }
    }
}
